import 'package:flutter/material.dart';
import 'package:flutter_psj/ui/particle/particle_weight.dart';
import 'package:simple_animations/simple_animations.dart';
import 'package:supercharged/supercharged.dart';

enum _ColorTween { color1, color2 }

class ParticlePage extends StatelessWidget {
  const ParticlePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("ParticlePage"),
      ),
      backgroundColor: Colors.black,
      body: Stack(children: const [
        Positioned.fill(child: AnimatedBackGround()),
        Positioned.fill(child: ParticlesWidget(30)),
        Positioned.fill(
            child: Center(
              child: Text(
                "Flutter Demo",
                style: TextStyle(
                  fontSize: 30,
                  fontWeight: FontWeight.bold,
                  color: Colors.white),
                ),
              ),
            )
      ],),
    );
  }
}

class AnimatedBackGround extends StatelessWidget {
  const AnimatedBackGround({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final tween = MultiTween<_ColorTween>()
      ..add(
          _ColorTween.color1,
          const Color(0xffD38312).tweenTo(Colors.lightBlue.shade900),
        3.seconds,
      )
      ..add(
        _ColorTween.color2,
        const Color(0xffA83279).tweenTo(Colors.blue.shade600),
        3.seconds,
      );

    return MirrorAnimation<MultiTweenValues<_ColorTween>>(
      tween: tween,
      duration: tween.duration,
      builder: (context, child, value) {
        return Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: [
                value.get<Color>(_ColorTween.color1),
                value.get<Color>(_ColorTween.color2)
              ]
            )
          ),
        );
      },
    );
  }
}

